﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LotteryVote.Logic;
using LotteryVote.Entity;
using LotteryVote.Utility;
using LotteryVote.Logic.Web;

namespace LotteryVote
{
    public partial class CommissionManager : CompanyPage
    {
        private IList<EnumDescriptionAttribute> _gameTypeList;
        public IList<EnumDescriptionAttribute> GameTypeList
        {
            get
            {
                if (_gameTypeList == null)
                    _gameTypeList = EnumHelper.GetDescription<GameTypeEnum>();
                return _gameTypeList;
            }
        }
        private IList<EnumDescriptionAttribute> _comTypeList;
        public IList<EnumDescriptionAttribute> CompanyTypeList
        {
            get
            {
                if (_comTypeList == null)
                    _comTypeList = EnumHelper.GetDescription<CompanyType>();
                return _comTypeList;
            }
        }
        CommisionGroupFacade groupFacade = new CommisionGroupFacade();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Execute(() =>
                {
                    BindLotterySpecies();
                });
            }

        }

        void BindLotterySpecies()
        {
            LotterySpecieFacade lsFacade = new LotterySpecieFacade();
            ddl_lotterySpecies.DataSource = lsFacade.GetAll();
            ddl_lotterySpecies.DataTextField = LotterySpecies.SPECIENAME;
            ddl_lotterySpecies.DataValueField = LotterySpecies.SPECIEID;
            ddl_lotterySpecies.DataBind();
        }


        protected void btn_AddGroup_Click(object sender, EventArgs e)
        {
            Execute(() =>
           {
               var commList = JSONHelper.ToObject<List<CommissionItem>>(hd_commission.Value);
               int specieId = int.Parse(ddl_lotterySpecies.SelectedValue);
               groupFacade.AddCommissionGroup(specieId, txt_groupName.Text, commList);
               ShowMessage("", GetGlobalResourceObject("Resource", "Success").ToString());
           });
        }
    }
}